package com.liang.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liang.common.lang.Result;
import com.liang.entity.CYun;
import com.liang.service.CYunService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 李昂
 * @since 2021-03-28
 */
@RestController
@RequestMapping("/cyun")
@AllArgsConstructor
public class CYunController {

    private CYunService yunService;

    //获取百度云资源链接
    @GetMapping("/source/{state}")
    public Result getResource(@RequestParam("name") String name,@PathVariable("state") int state) {

        Page<CYun> page = new Page<>(state, 20, true);
        return Result.succ(yunService.getResource(page,name,state));
    }

    //删除无效链接
    @DeleteMapping("/source/{id}")
    public Result deleteResource(@PathVariable("id") int id) {
        if (yunService.deleteResource(id)) {
            return Result.succ();
        } else {
            return Result.fail();
        }
    }

}
